package tt.love.hw.action;

import java.io.IOException;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;

import tt.love.hw.PMF;
import tt.love.hw.common.ActionContext;
import tt.love.hw.common.DirectViewRender;
import tt.love.hw.common.ViewRender;
import tt.love.hw.jdo.User;

public class UserAction {


	public ViewRender register(ActionContext actionContext)
			throws ServletException, IOException {
		
		User husband = (User)actionContext.get("husband");
		User wife = (User)actionContext.get("wife");
		husband.setMateUserId(wife.getUserId());
		husband.setRole("H");
		wife.setMateUserId(husband.getUserId());
		wife.setRole("W");
		
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			pm.makePersistent(husband);
			pm.makePersistent(wife);
		}finally {
			pm.close();
		}
        return new DirectViewRender("/login.jsp");
	}
}
